package com.ruoyi.camp.api;

import com.ruoyi.camp.domain.CActivity;
import com.ruoyi.camp.service.ICActivityService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 营地活动Controller
 * 
 * @author ruoyi
 * @date 2024-10-29
 */
@RestController
@RequestMapping("/wechat/activity")
public class WxCActivityController extends BaseController
{
    @Autowired
    private ICActivityService cActivityService;
    @GetMapping("/getInfoByCampId/{campid}")
    public AjaxResult getInfoByCampId(@PathVariable("campid") String campid) {
        if (campid == null) {
            return error("营地Id不能为空");
        }
        List<CActivity> list = cActivityService.getInfoByCampId(campid);
        return success(list);
    }
    @GetMapping("/getInfoByActivityId/{activityid}")
    public AjaxResult getInfoByScenicId(@PathVariable("activityid") String activityid) {
        if (activityid == null) {
            return error("活动Id不能为空");
        }
        CActivity wxActivity = cActivityService.getInfo(activityid);
        return success(wxActivity);
    }
    /**
     * 新增营地活动
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody CActivity cActivity){
        if (cActivity == null) {
            return error("数据不能为空");
        }
        if (cActivity.getCampid() == null) {
            return error("营地Id不能为空");
        }
        if (cActivity.getActivityname() == null) {
            return error("活动名称不能为空");
        }
        if (cActivity.getOriginalprice() == null) {
            return error("原价不能为空");
        }
        System.out.println(cActivity);
        return toAjax(cActivityService.insertCActivity(cActivity));
    }
    /**
     * 修改营地活动
     */
    @PutMapping("/update")
    public AjaxResult update(@RequestBody CActivity cActivity) {
        if (cActivity == null) {
            return error("数据不能为空");
        }
        if (cActivity.getActivityid() == null) {
            return error("营地活动Id不能为空");
        }
        if (cActivity.getCampid() == null) {
            return error("营地Id不能为空");
        }
        if (cActivity.getActivityname() == null) {
            return error("活动名称不能为空");
        }
        if (cActivity.getOriginalprice() == null) {
            return error("原价不能为空");
        }
        return toAjax(cActivityService.updateCActivity(cActivity));
    }
    /**
     * 删除营地活动
     */
    @DeleteMapping("/delete/{activityid}")
    public AjaxResult delete(@PathVariable("activityid") String activityid){
        if (activityid == null) {
            return error("活动Id不能为空");
        }
        return toAjax(cActivityService.deleteCActivityByActivityid(activityid));
    }
}
